<template>
    <div>
        <el-dialog :title="'工作流程任务配置'" :visible.sync="dialogVisible" width="1250px" :close-on-click-modal="false">
            <el-row :span="24">
                <el-col :span="2" style="line-height: 45px">
                    <b>业务环节名称:</b>
                </el-col>
                <el-col :span="10">
                    <el-input v-model="taskName" style="width:100%; margin: 0 0 0 10px;" type="text" placeholder="请输入内容" />
                </el-col>
                <el-col :span="6" style="margin-left: 30px">
                    <el-button type="primary" size="small" @click="findBytaskName()" >查询</el-button>&nbsp;&nbsp;
                    <el-button type="info" size="small" @click="resets()" >重置</el-button>
                </el-col>
            </el-row>
            <br>
            <el-row :span="12">
                <el-button type="primary" size="small" @click="flowAddconfig()">新增</el-button>&nbsp;&nbsp;
<!--                <el-button type="warning" size="small" @click="synchronous()" >获取同类型数据</el-button>-->
            </el-row>
            <br>
            <el-table stripe :data="assessInfoData" align="center" class="flowTable">
                <el-table-column label="序号" type="index" width="75" align="center"/>
                <el-table-column label="业务环节名称" prop="taskName" width="150" align="center"/>
                <el-table-column label="业务环节代码" prop="taskCode" width="120" align="center" />
                <el-table-column label="正常办理周期 (天)" prop="normalDay" width="150" align="center" />
                <el-table-column label="预警周期 （天）" prop="warnDay" width="150" align="center" />
                <el-table-column label="操作" align="center" width="225">
                    <template slot-scope="scope">
                        <el-button  type="text" @click="updateConfig(scope.row)"> 修改</el-button>
                        <el-button  type="text" @click="deleteConfig(scope.row.taskConfId)" > 删除</el-button>
                        <el-button  type="text" @click="Configuration(scope.row.taskConfId)"> 办理配置结果  </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-row :span="12" style="margin-top: 30px;text-align:right;">
                <el-button type="primary" @click="dialogVisible=false">关闭</el-button>
            </el-row>
            <flow-configuration ref="flowConfiguration" />
            <flow-addconfig ref="flowAddconfig" v-on:flowTaskConf="getList" />
            <flow-updateconfig ref="flowUpdateconfig" v-on:flowTaskConf="getList" />
        </el-dialog>
    </div>
</template>

<script>
    import dbl from '@/utils/dbl'
    import flowConfiguration from './flow-configuration'
    import flowAddconfig from './flow-Addconfig'
    import flowUpdateconfig from './flow-Updateconfig' 
    import axios from 'axios'

    import {delConfig} from '@/views/wy-flow/api/actreprocdef'

    export default {
        name: "flow-config",
        components: { flowConfiguration,flowAddconfig,flowUpdateconfig},
        data() {
            return {
                dialogVisible: false,
                assessInfoData: [],
                flowprocDefId:'',
                version:'',
                isAuto:'',
                taskName:'',
                keys:'',
            }
        },
        methods: {

            show(data,version,keys) {
                this.dialogVisible = true
                this.keys=keys
                this.flowprocDefId=data
                this.version=version
                this.getList(data)
            },
            getList(keys){
                // var data = new FormData()
                // data.append('procDefId',keys )
                // alert("ss")
                const config = {
                    headers: { 'Authorization': dbl.get('token'),}
                }
                axios.get("/api/flowTaskConf/toList?procDefId="+keys, config).then(response => {
                    this.assessInfoData=response.data.data.records
                }).catch(e => {

                })
            },
            deleteConfig(taskConfId){ // 删除
                var thta=this;
                this.$confirm('是否确认删除?' , '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {
                    // alert(taskConfId)
                    return delConfig(taskConfId)
                }).then(data => {
                    this.$message.success('删除成功')
                    thta.getList(thta.flowprocDefId)
                })
            },
            updateConfig(data){ // 修改
                this.$refs.flowUpdateconfig.show(data)
         },
            Configuration(data){  //流程配置
                this.$refs.flowConfiguration.show(data)
            },
            flowAddconfig(){  // 新增
                this.$refs.flowAddconfig.show(this.flowprocDefId)
            },
            synchronous(){ // 同步数据
                var thta=this
                const config = {
                    headers: { 'Authorization': dbl.get('token'),}
                }
                axios.get("/api/flowTaskConf/getSameData/"+this.keys+"/"+this.flowprocDefId, config).then(response => {
                    if(response.data.msg=='获取数据成功。'){
                        this.$message.success(response.data.msg)
                        thta.getList(thta.flowprocDefId)
                    }
                    else{
                        this.$message.warning(response.data.msg)
                    }

                }).catch(e => {
                    this.$message.error('获取失败')
                })

            },
            findBytaskName(){ // 查询
                const config = {
                    headers: { 'Authorization': dbl.get('token'),}
                }

                var   keys="?procDefId="+this.flowprocDefId
                if(this.taskName!=''){
                    keys+="&taskName="+this.taskName
                }
                axios.get("/api/flowTaskConf/toList"+keys, config).then(response => {
                    this.assessInfoData=response.data.data.records
                }).catch(e => {
                })
            },
            resets(){ // 重置
                this.taskName='',
                this.isAuto=''
            }


        }
    }
</script>

<style scoped lang='scss'>
    

    @include formWrap(4);
</style>

